home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / test / test_applesingle.py < prev    next >
Text File  |  2005-10-18  |  2KB  |  73 lines

  1. # Copyright (C) 2003 Python Software Foundation
  2.  
  3. import unittest
  4. import macostools
  5. import Carbon.File
  6. import MacOS
  7. import os
  8. import sys
  9. from test import test_support
  10. import struct
  11. import applesingle
  12.  
  13. AS_MAGIC=0x00051600
  14. AS_VERSION=0x00020000
  15. dataforkdata = 'hello\r\0world\n'
  16. resourceforkdata = 'goodbye\ncruel\0world\r'
  17.  
  18. applesingledata = struct.pack("ll16sh", AS_MAGIC, AS_VERSION, "foo", 2) + \
  19.     struct.pack("llllll", 1, 50, len(dataforkdata),
  20.         2, 50+len(dataforkdata), len(resourceforkdata)) + \
  21.     dataforkdata + \
  22.     resourceforkdata
  23. TESTFN2 = test_support.TESTFN + '2'
  24.  
  25. class TestApplesingle(unittest.TestCase):
  26.  
  27.     def setUp(self):
  28.         fp = open(test_support.TESTFN, 'w')
  29.         fp.write(applesingledata)
  30.         fp.close()
  31.  
  32.     def tearDown(self):
  33.         try:
  34.             os.unlink(test_support.TESTFN)
  35.         except:
  36.             pass
  37.         try:
  38.             os.unlink(TESTFN2)
  39.         except:
  40.             pass
  41.  
  42.     def compareData(self, isrf, data):
  43.         if isrf:
  44.             fp = MacOS.openrf(TESTFN2, '*rb')
  45.         else:
  46.             fp = open(TESTFN2, 'rb')
  47.         filedata = fp.read(1000)
  48.         self.assertEqual(data, filedata)
  49.  
  50.     def test_applesingle(self):
  51.         try:
  52.             os.unlink(TESTFN2)
  53.         except:
  54.             pass
  55.         applesingle.decode(test_support.TESTFN, TESTFN2)
  56.         self.compareData(False, dataforkdata)
  57.         self.compareData(True, resourceforkdata)
  58.  
  59.     def test_applesingle_resonly(self):
  60.         try:
  61.             os.unlink(TESTFN2)
  62.         except:
  63.             pass
  64.         applesingle.decode(test_support.TESTFN, TESTFN2, resonly=True)
  65.         self.compareData(False, resourceforkdata)
  66.  
  67. def test_main():
  68.     test_support.run_unittest(TestApplesingle)
  69.  
  70.  
  71. if __name__ == '__main__':
  72.     test_main()
  73.